<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="/">
	<xsl:apply-templates />
</xsl:template>

<xsl:template match="/Tree">
  <xsl:if test="@caption">
     <span>
       <img align="absmiddle">
       <xsl:attribute name="src"><xsl:eval>pathImg("openfolder1.gif")</xsl:eval></xsl:attribute>       
       </img>
       <b><u><xsl:value-of select="@caption" /></u></b>
     </span>
  </xsl:if>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="TreeNode[@IsLeaf=1]">
   <table border="0" cellspacing="0" cellpadding="0">
      <xsl:attribute name="width"><xsl:eval>getWidth(this)</xsl:eval></xsl:attribute>
      <tr>
	<td valign="middle">
	    <xsl:eval no-entities="yes">getImgs(this)</xsl:eval>
            <img>
               <xsl:attribute name="src"><xsl:eval>getFirstImg(this,false)</xsl:eval></xsl:attribute>
	       <xsl:attribute name="align">absmiddle</xsl:attribute>
	       <xsl:attribute name="border">0</xsl:attribute>
	    </img>

            <img>
               <xsl:attribute name="src"><xsl:eval>getSecImg(this,"item1.gif")</xsl:eval></xsl:attribute>
	       <xsl:attribute name="align">absmiddle</xsl:attribute>
	       <xsl:attribute name="border">0</xsl:attribute>
            </img>

            <xsl:choose>
               <xsl:when test="@Href">
                 <a>
                   <xsl:if test="@tooltips">
                     <xsl:attribute name="title"><xsl:value-of select="@tooltips" /></xsl:attribute>
                   </xsl:if>

                   <xsl:choose>
                     <xsl:when test="@Target">
                       <xsl:attribute name="target"><xsl:value-of select="@Target" /></xsl:attribute>
                     </xsl:when>
                   </xsl:choose>

                   <xsl:attribute name="tabindex">-1</xsl:attribute>
                   <xsl:attribute name="href"><xsl:value-of select="@Href" /></xsl:attribute>

		   <span type="label" style="cursor:handle">
		      <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		      <xsl:value-of select="@Title" />
		  </span>
                </a>
              </xsl:when>

	      <xsl:when test="@Action">
                <a>
                   <xsl:if test="@tooltips">
                     <xsl:attribute name="title"><xsl:value-of select="@tooltips" /></xsl:attribute>
                   </xsl:if>

                  <xsl:attribute name="tabindex">-1</xsl:attribute>
	          <xsl:attribute name="style">cursor:hand</xsl:attribute>
                  <xsl:attribute name="onclick"><xsl:value-of select="@Action" /></xsl:attribute>
                  <span type="label" style="cursor:handle">
		      <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		      <xsl:value-of select="@Title" />
		  </span>
                </a>
              </xsl:when>

	      <xsl:when test="@onLoad">
	         <script language="javascript">
		   <xsl:value-of select="@onLoad" />;
		 </script>
		 <span type="label" style="cursor:handle">
		      <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		      <xsl:value-of select="@Title" />
		  </span>
              </xsl:when>

              <xsl:otherwise>
                <span type="label" style="cursor:handle">
		      <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		      <xsl:value-of select="@Title" />
		</span>
              </xsl:otherwise>
            </xsl:choose>
	</td>
      </tr>
   </table>
</xsl:template>

<xsl:template match="TreeNode[@IsLeaf=0]">
   <div>
   <xsl:attribute name="ID">mm_<xsl:value-of select="@id" />_Parent</xsl:attribute>
   <xsl:attribute name="xmlsrc"><xsl:value-of select="@NodeXmlSrc" /></xsl:attribute>
   <xsl:attribute name="child_pre"><xsl:value-of select="@child_pre" /></xsl:attribute>
   <table border="0" cellspacing="0" cellpadding="0">
      <xsl:attribute name="width"><xsl:eval>getWidth(this)</xsl:eval></xsl:attribute>
      <tr>
	<td valign="middle"><xsl:eval no-entities="yes">getImgs(this)</xsl:eval><a type="expand_icon"><xsl:attribute name="ID">mm_<xsl:value-of select="@id" />_a</xsl:attribute>
	    <xsl:attribute name="pid"><xsl:value-of select="@id" /></xsl:attribute>
	    <xsl:attribute name="pos"><xsl:eval>isLast(this)</xsl:eval></xsl:attribute>
	    <xsl:attribute name="pre"><xsl:value-of select="@pre" /></xsl:attribute>
	    <xsl:attribute name="style">cursor:hand</xsl:attribute><img type="expand_icon">
               <xsl:attribute name="src"><xsl:eval>getFirstImg(this,true)</xsl:eval></xsl:attribute>
	       <xsl:attribute name="align">absmiddle</xsl:attribute>
	       <xsl:attribute name="border">0</xsl:attribute>
	    </img><img type="expand_icon">
               <xsl:attribute name="src"><xsl:eval>getSecImg(this,"folder1.gif")</xsl:eval></xsl:attribute>
	       <xsl:attribute name="oldsrc"><xsl:eval>getOpenSecImg(this,"folder1.gif")</xsl:eval></xsl:attribute>
	       <xsl:attribute name="align">absmiddle</xsl:attribute>
	       <xsl:attribute name="border">0</xsl:attribute></img>
	   </a>
            <xsl:choose>
               <xsl:when test="@Href">
                 <a>
                   <xsl:if test="@tooltips">
                     <xsl:attribute name="title"><xsl:value-of select="@tooltips" /></xsl:attribute>
                   </xsl:if>

                   <xsl:choose>
                     <xsl:when test="@Target">
                       <xsl:attribute name="target"><xsl:value-of select="@Target" /></xsl:attribute>
                     </xsl:when>
                   </xsl:choose>
                   <xsl:attribute name="tabindex">-1</xsl:attribute>
                   <xsl:attribute name="href"><xsl:value-of select="@Href" /></xsl:attribute>
		   <span type="label" style="cursor:handle">
		      <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		      <xsl:value-of select="@Title" />
		   </span>
                </a>
              </xsl:when>
	      <xsl:when test="@Action">
                <a>
                   <xsl:if test="@tooltips">
                     <xsl:attribute name="title"><xsl:value-of select="@tooltips" /></xsl:attribute>
                   </xsl:if>

                  <xsl:attribute name="tabindex">-1</xsl:attribute>
	          <xsl:attribute name="style">cursor:hand</xsl:attribute>
                  <xsl:attribute name="onclick"><xsl:value-of select="@Action" /></xsl:attribute>
                  <span type="label" style="cursor:handle">
		      <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		      <xsl:value-of select="@Title" />
		  </span>
                </a>
              </xsl:when>
	      <xsl:when test="@onLoad">
	         <script language="javascript">
		   <xsl:value-of select="@onLoad" />;
		 </script>
		 <span type="label" style="cursor:handle">
		      <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		      <xsl:value-of select="@Title" />
		  </span>
              </xsl:when>
              <xsl:otherwise>
                 <span type="label" style="cursor:handle">
		      <xsl:attribute name="id">mm_<xsl:value-of select="@id" />_Label</xsl:attribute>
		      <xsl:value-of select="@Title" />
		  </span>
              </xsl:otherwise>
            </xsl:choose>
	</td>
      </tr>
   </table>
  </div>
  <div>
     <xsl:attribute name="ID">mm_<xsl:value-of select="@id" />_Child</xsl:attribute>
     <xsl:attribute name="style">display:none</xsl:attribute>
     <xsl:choose>
        <xsl:when test="@NodeXmlSrc">
	    &#160;
	</xsl:when>
	<xsl:otherwise>
	   <xsl:apply-templates/>
	</xsl:otherwise>
     </xsl:choose>
  </div>
</xsl:template>

<xsl:template match="@Target">
  <xsl:copy><xsl:value-of /></xsl:copy>
</xsl:template>

<xsl:template match="/TreeNode">
  <xsl:apply-templates/>
</xsl:template>
<xsl:template match="TreeNode/Tree">
  <xsl:apply-templates />
</xsl:template>

<xsl:script><![CDATA[

var rootNode=this.selectSingleNode("/Tree");
var root = rootNode.getAttribute("imgpath");
var str1="<img src=\"";
var str2="\" align=\"absmiddle\" border=\"0\">";

function getFirstImg(_oSrc,flag)
{
    if(flag)
    {
       if(_oSrc.nextSibling==null) return pathImg("Lplus.gif");
       else return pathImg("Tplus.gif");
    }
    else
    {
       if(_oSrc.nextSibling==null) return pathImg("L.gif");
       else return pathImg("T.gif");
    }
}

function getSecImg(_oSrc,icon)
{
    var str=_oSrc.getAttribute("Icon");
    if(str==null || str=="") str=icon;
    return pathImg(str);
}
function getOpenSecImg(_oSrc,icon)
{
    var str=_oSrc.getAttribute("Icon");
    if(str==null || str=="") str=icon;
    return pathImg("open"+str);
}

function isLast(_oSrc)
{
    if(_oSrc.nextSibling==null) return "last";
    else return "null";
}

function pathImg( __strImg )
{
	path = root + __strImg;
	return path;
}

function getImg(_flag)
{
    if(_flag=="1") return str1+pathImg("I.gif")+str2;
    else return str1+pathImg("white.gif")+str2;
}

function getImgs(_oSrc)
{
     var imgText="";
     var ch=null;
     var poss=_oSrc.getAttribute("pre");
     for(i=0;i<poss.length;i++)
     {
            ch=poss.substring(i,i+1);
	    imgText=imgText+getImg(ch);
     }
     return imgText;
}

function getWidth(_oSrc)
{
    var level=_oSrc.getAttribute("pre").length+2;
    var c_len=_oSrc.getAttribute("Title").length;;
    return level*26+c_len*14;
}
]]></xsl:script>
</xsl:stylesheet>
